package com.geostar.constructionland.analyse.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.geostar.constructionland.common.entity.analyse.AnalyseVersion;
import com.geostar.constructionland.analyse.entity.model.AnalyseModel;
import com.geostar.constructionland.analyse.mapper.sptalyresult.AnalyseVersionMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author yelll
 * @since 2020-5-28 14:08
 **/
@Service
@Slf4j
public class AlyVerService {
    @Autowired
    AnalyseVersionMapper alyVerMapper;
    public AnalyseVersion getAlyVerByAnalyModel(AnalyseModel analyseModel) throws Exception {
        QueryWrapper<AnalyseVersion> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("analyse_type",analyseModel.getFxlxMapped());
        AnalyseVersion analyseVersion = null;
        if(StringUtils.isBlank(analyseModel.getAnalyseVersion())){
            log.info("未传入分析版本号，分析类型："+analyseModel.getFxlxMapped());
            List<AnalyseVersion> analyseVersions =
                    alyVerMapper.selectList(queryWrapper.orderByDesc("version_no"));
            if(analyseVersions.size()>0){
                analyseVersion = analyseVersions.get(0);
                /**设置当前的版本信息*/
                analyseModel.setAnalyseVersion(analyseVersion.getVersionNo());
            }
        }else {
            queryWrapper.eq("version_no",analyseModel.getAnalyseVersion());
            analyseVersion = alyVerMapper.selectOne(queryWrapper);
        }
        if(analyseVersion==null){
            throw  new Exception("没有找到相应的分析版本信息");
        }
        return analyseVersion;
    }
}
